package org.west.sky.frame.activiti.study.chapter16;

import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.west.sky.frame.activiti.study.util.ActivitiEngineUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * author: chz
 * date: 2025/6/6
 * description: 并行网关
 */
public class RunDemo16_2_2 extends ActivitiEngineUtil {

    public static void main(String[] args) {
        RunDemo16_2_2 runDemo16_1_2 = new RunDemo16_2_2();
        runDemo16_1_2.run();
    }

    public void run() {
        loadActivitiConfigAndInitEngine();
        ProcessDefinition processDefinition = deployByClassPathResource("processes/chapter16/Chapter16_2_2.bpmn20.xml");

        ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());

        List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
        for (Task task : tasks) {
            System.out.println("====当前流程：" + processInstance.getId() + "进行到：" + task.getName() + "：任务节点");
            taskService.complete(task.getId());
        }

        List<Task> tasks2 = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
        for (Task task : tasks2) {
            System.out.println("====当前流程：" + processInstance.getId() + "进行到：" + task.getName() + "：任务节点");
            taskService.complete(task.getId());
        }

        closeEngine();
    }
}
